<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置编辑--${site.name}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${base}/static/layui/css/layui.css" media="all" />
</head>
<body class="childrenBody">
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
  <ul class="layui-tab-title">
    <li class="layui-this">系统设置</li>
    <li>微信设置</li>
    <li>订单设置</li>
  </ul>
  <div class="layui-tab-content" style="height: 100px;">
    <div class="layui-tab-item layui-show">
    	<form class="layui-form" >
		    <input value="system" name="type" type="hidden">
		    <div class="layui-form-item">
		        <label class="layui-form-label"> <span class="required">*</span>  文件保存路径</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input" name="systemSavePath" lay-verify="required" placeholder="请输入文件保存路径">
		
		        </div>
		    </div>
		   <div class="layui-form-item">
		        <label class="layui-form-label"> <span class="required">*</span>  文件访问前缀</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input"  name="systemPrefix" lay-verify="required" placeholder="请输入文件访问前缀">
		
		        </div>
		    </div>
		    <div class="layui-form-item">
		        <div class="layui-input-block">
		            <button class="layui-btn" lay-submit="" lay-filter="saveSystem">保存</button>
		        </div>
		    </div>
		</form>
    </div>
    <div class="layui-tab-item">
    	<form class="layui-form" >
		    <input value="weixin" name="type" type="hidden">
		    <div class="layui-form-item">
		        <label class="layui-form-label"> <span class="required">*</span> appid</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input" value = "" name="wxAppid" lay-verify="required" placeholder="小程序appid">
		
		        </div>
		    </div>
		   <div class="layui-form-item">
		        <label class="layui-form-label"> <span class="required">*</span> secret</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input"name="wxSecret" lay-verify="required" placeholder="小程序secret">
		
		        </div>
		    </div>
		    <div class="layui-form-item">
		        <label class="layui-form-label">mchId</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input"  name="wxMchId" placeholder="微信支付商户号">
		
		        </div>
		    </div>
		     <div class="layui-form-item">
		        <label class="layui-form-label">mchKey</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input" name="wxMchKey" placeholder="微信支付key">
		
		        </div>
		    </div>
		     <div class="layui-form-item">
		        <label class="layui-form-label">支付通知地址</label>
		        <div class="layui-input-block">
		                <input  type="text" class="layui-input" name="wxPayNotifyUrl" placeholder="微信支付成功回调地址">
		
		        </div>
		    </div>
		    <div class="layui-form-item">
		        <div class="layui-input-block">
		            <button class="layui-btn" lay-submit="" lay-filter="saveWeixin">保存</button>
		        </div>
		    </div>
		</form>
    </div>
    <div class="layui-tab-item">
    	<form class="layui-form" >
		    <input value="order" name="type" type="hidden">
		    <div class="layui-form-item">
		        <label class="layui-form-label"> <span class="required">*</span>下单后多久未付款自动取消</label>
		        <div class="layui-input-inline">
		                <input  type="number" class="layui-input" value = "" name="orderAutoCancleHour"  placeholder="订单付款超时时间">
		        </div>
		         <div class="layui-form-mid layui-word-aux">小时</div>
		    </div>
		   <div class="layui-form-item">
		        <label class="layui-form-label"> <span class="required">*</span>订单发货后多久未确认系统 自动确认收货</label>
		        <div class="layui-input-inline">
		                <input  type="number" class="layui-input"  name="orderAutoReceiveDay" lay-verify="required" placeholder="订单确认收货超时时间">
		        </div>
		        <div class="layui-form-mid layui-word-aux">天</div>
		    </div>
		    <div class="layui-form-item">
		        <div class="layui-input-block">
		            <button class="layui-btn" lay-submit="" lay-filter="saveOrder">保存</button>
		        </div>
		    </div>
		</form>
    </div>
  </div>
<script type="text/javascript" src="${base}/static/layui/layui.js"></script>
<script>
    layui.use(['form','element','layer'],function(){
        var form      = layui.form,
                $     = layui.jquery,
                layer = layui.layer;
        
        //系统设置保存
        form.on("submit(saveSystem)",function(data){
            //保存
            save(data.field.type,data.field);
            return false;
        });
      //订单设置保存
        form.on("submit(saveOrder)",function(data){
            //保存
            save(data.field.type,data.field);
            return false;
        });
      //微信设置保存
        form.on("submit(saveWeixin)",function(data){
            //保存
            save(data.field.type,data.field);
            return false;
        });
        
        //加载系统设置数据
        loadData('system',function(json){
        	$('input[name=systemSavePath]').val(json.systemSavePath);
        	$('input[name=systemPrefix]').val(json.systemPrefix);
        });
        
      //加载订单设置数据
        loadData('order',function(json){
        	$('input[name=orderAutoCancleHour]').val(json.orderAutoCancleHour);
        	$('input[name=orderAutoReceiveDay]').val(json.orderAutoReceiveDay);
        });
        
      //加载微信设置数据
        loadData('weixin',function(json){
        	$('input[name=wxAppid]').val(json.wxAppid);
        	$('input[name=wxSecret]').val(json.wxSecret);
        	$('input[name=wxMchId]').val(json.wxMchId);
        	$('input[name=wxMchKey]').val(json.wxMchKey);
        	$('input[name=wxPayNotifyUrl]').val(json.wxPayNotifyUrl);
        });
        
        function save(type,json) {
        	 var loadIndex = layer.load(2, {
                 shade: [0.3, '#333']
             });
             $.post("${base}${adminPrefix}/common-setting/update",{type:type,json:JSON.stringify(json)},function(res){
                 layer.close(loadIndex);
                 if(res.success){
                 	layer.msg("保存成功！");
                 }else{
                     layer.msg(res.message);
                 }
             });
        }
        
        function loadData(type,callback) {
        	 $.get("${base}${adminPrefix}/common-setting/detail",{type:type},function(res){
                 if(res.success){
                	 callback(JSON.parse(res.data.json));
                 }else{
                     layer.msg(res.message);
                 }
             });
        }

    });
</script>
</body>
</html>